package com.forum.controller;

import com.forum.service.impl.OssServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName OssController
 * @Description TODO
 * @Author suyao
 * @Version 1.0
 */
@RestController
@CrossOrigin
@RequestMapping("/file")
public class OssController {
    @Autowired
    private OssServiceImpl ossService;

    //上传文件，返回url
    @ApiOperation(value = "上传文件到oss")
    @PostMapping("/addFile")
    public String uploadOssFile(MultipartFile file) throws Exception{
        //获取上传文件 MultipartFile
        //返回图片在oss上的路径
        String url = ossService.uploadFileAvatar(file);
        return url;
    }

}
